When programming in some languages, it is a common practice to include constructs called preprocessor directives or preprocessor directive statements in the source code. Preprocessor directives are evaluated by a preprocessor before the source code is compiled. Typically, the source code with the preprocessor directives in it is provided to a preprocessor that takes the source code file with the preprocessor directives, makes appropriate substitutions and outputs a source code file without preprocessor directives. Because preprocessor directives are not legal code, the preprocessor directives have to be evaluated and removed before the source code will compile correctly.
A preprocessor can add useful features to the programming language in which the source code is written. For example, a preprocessor can receive configuration variables, and using the configuration variables, configure the program to run on a particular platform. There is also the potential for the preprocessor to output source code from which information available in the input source code has been lost. For example, to configure a program to run on a particular platform, typically the preprocessor evaluates preprocessor conditional directive statements. Based on the information provided in the configuration variables, the preprocessor selects a single branch of each preprocessor conditional directive statement to process and ignores the other branch or branches. Thus, information available in the other branches of the preprocessor conditional directive statements in the input source code may be lost when the source code is processed by the preprocessor.
The presence of the preprocessor directives in the input source code directs the preprocessor to perform certain operations, one of which is conditional compilation. Conditional compilation refers to a technique for compiling code selectively depending on the value of conditions evaluated during compilation.
In some programming languages (such as C, for example), preprocessor directive lines are those lines that start with a specified character or combination of characters. For C, for example, “#” denotes a preprocessor directive line. Conditional preprocessor directive lines in C source code are those that start with #if, #ifdef, #ifndef, #elif, #else, #endif. The text in between each preprocessor conditional directive line can be any text, including other preprocessor directives, or there may be no text in between preprocessor conditional directive lines. Standard C preprocessors evaluate the conditions and eliminate the text for which conditions are false, along with preprocessor conditional directive lines. Discarding the portions of code in the unprocessed branches can, however, result in errors.